import java.rmi.RemoteException;

import FlexTrade.AuctionPrimitiveData;
import FlexTrade.AuctionStates;
import FlexTrade.IAuction;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OtherStatesDlg.java
 *
 * Created on May 17, 2012, 7:18:45 PM
 */

/**
 *
 * @author hieuht
 * User interface that holds information about existing English/Vickrey auctions
 */
public class OtherStatesDlg extends javax.swing.JDialog {

    /** Creates new form OtherStatesDlg */
    public OtherStatesDlg(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
    	this.setTitle("Vickrey/English Auction Status");
        btnExit = new javax.swing.JButton();
        lblAuctionID = new javax.swing.JLabel();
        lblProduct = new javax.swing.JLabel();
        lblHighestPrice = new javax.swing.JLabel();
        lbl2ndHighestPrice = new javax.swing.JLabel();
        lblTimeLeft = new javax.swing.JLabel();
        txtAuctionID = new javax.swing.JTextField();
        txtProduct = new javax.swing.JTextField();
        txtHighestPrice = new javax.swing.JTextField();
        txt2ndHighestPrice = new javax.swing.JTextField();
        
        txtAuctionID.setEditable(false);
        txtProduct.setEditable(false);
        txtHighestPrice.setEditable(false);
        txt2ndHighestPrice.setEditable(false);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btnExit.setText("Exit");
        btnExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExitActionPerformed(evt);
            }
        });

        lblAuctionID.setText("Auction ID");

        lblProduct.setText("Product");

        lblHighestPrice.setText("Highest Price");

        lbl2ndHighestPrice.setText("Second Highest Price");

        lblTimeLeft.setText("Time Left");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblAuctionID)
                            .addComponent(lblProduct)
                            .addComponent(lblHighestPrice)
                            .addComponent(lbl2ndHighestPrice))
                        .addGap(58, 58, 58)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txt2ndHighestPrice)
                            .addComponent(txtHighestPrice)
                            .addComponent(txtProduct)
                            .addComponent(txtAuctionID, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(169, 169, 169)
                        .addComponent(btnExit, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(185, 185, 185)
                        .addComponent(lblTimeLeft)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAuctionID)
                    .addComponent(txtAuctionID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblProduct)
                    .addComponent(txtProduct, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblHighestPrice)
                    .addComponent(txtHighestPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbl2ndHighestPrice)
                    .addComponent(txt2ndHighestPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(lblTimeLeft)
                .addGap(18, 18, 18)
                .addComponent(btnExit)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        


        pack();
    }// </editor-fold>

    private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    	this.dispose();
    }
    
    public void setUniqueAuctionID(String _uniqueAuctionID){
    	this.uniqueAuctionID = _uniqueAuctionID;
    	//get the auction with _uniqueAuctionID
        this.activeAuction = Provider.lookUpCurrentAuction(this.uniqueAuctionID);
        try {
			AuctionStates auctionState = this.activeAuction.getCurrentAuctionStates();
			AuctionPrimitiveData auctionPrimitiveData = this.activeAuction.getAuctionPrimitiveData();
			this.txtProduct.setText(auctionPrimitiveData.product.getProductName());
			this.txtAuctionID.setText(this.uniqueAuctionID);
			this.txtHighestPrice.setText(Float.toString(auctionState.highestBidPrice));
			this.txt2ndHighestPrice.setText(Float.toString(auctionState.secondHighestBidPrice));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
    	
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OtherStatesDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OtherStatesDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OtherStatesDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OtherStatesDlg.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                OtherStatesDlg dialog = new OtherStatesDlg(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton btnExit;
    private javax.swing.JLabel lbl2ndHighestPrice;
    private javax.swing.JLabel lblAuctionID;
    private javax.swing.JLabel lblHighestPrice;
    private javax.swing.JLabel lblProduct;
    private javax.swing.JLabel lblTimeLeft;
    private javax.swing.JTextField txt2ndHighestPrice;
    private javax.swing.JTextField txtAuctionID;
    private javax.swing.JTextField txtHighestPrice;
    private javax.swing.JTextField txtProduct;
    // End of variables declaration
    String uniqueAuctionID;
    IAuction activeAuction = null;
    Provider provider = null;
}
